###################################################
### code chunk number : Power-log loss function
###################################################
## 
##
## L[pl](x)
rm(list=ls(all=TRUE))
theta = 0.2
n = 10
L_pl_x = function(x) (1/theta - 1)^2 / (1/theta - x) - log(x) - (1/theta - 1)
k1_theta = theta * (1/theta - 1)^2; k1_theta
x = seq(exp(-k1_theta * n), 1/theta * (1 - 1/n), length.out = 1000)
y = L_pl_x(x) 
# xp = c(exp(-k1_theta * (n:2)), 1, 1/theta * (1 - 1 / (2:n)))
# yp = L_pl_x(xp)
xlim = c(0, 1/theta)
plot(x, y, xlab = expression( x ), ylab = expression( L[pl](x) ), xlim = xlim, type = "l", lwd = 4, sub = "(a)")
# points(xp, yp, pch = c((n-1):1, 0, 1:(n-1)), col = "red", lwd = 2)
abline(h = 0, lty = "dashed")
abline(v = c(0, 1/theta), lty = "dashed")
savePlot(filename = "figure/y_pl_x", type = c("pdf"))
savePlot(filename = "figure/y_pl_x", type = c("jpg"))
## L[pl](theta, a)
rm(list=ls(all=TRUE))
theta = 0.2
n = 10
L_pl_a = function(theta, a) theta * (1/theta - 1)^2 / (1 - a) - log(a) + log(theta) - (1/theta - 1)
k2_theta = theta * (1/theta - 1)^2; k2_theta ## k2_theta = k1_theta
a = seq(theta * exp(-k2_theta * n), (1 - 1/n), length.out = 1000)
y = L_pl_a(theta, a) 
# ap = c(theta * exp(-k2_theta * (n:2)), theta, 1 - 1 / (2:n))
# yp = L_pl_a(theta, ap)
xlim = c(0, 1)
dev.new()
plot(a, y, xlab = expression( a ), ylab = expression( paste(L[pl], "(", theta, ", a)") ), xlim = xlim, type = "l", lwd = 4, sub = "(b)")
# points(ap, yp, pch = c((n-1):1, 0, 1:(n-1)), col = "red", lwd = 2)
abline(h = 0, lty = "dashed")
abline(v = c(0, 1), lty = "dashed")
savePlot(filename = "figure/y_pl_theta_a", type = c("pdf"))
savePlot(filename = "figure/y_pl_theta_a", type = c("jpg"))
###################################################
### code chunk number : Zhang's loss function
###################################################
## 
## (a): L_z(x)
rm(list=ls(all=TRUE))
theta = 0.2
n = 10
L_z_x = function(x) 1/((1/theta - 1)^2 * x) + 1/(1/theta - x) - 1/ (theta * (1/theta - 1)^2)
k1_theta = 1/(theta * (1/theta - 1)^2); k1_theta
x = seq(k1_theta * 1/n, 1/theta * (1 - 1/n), length.out = 50)
y = L_z_x(x) 
xp = c(k1_theta * 1 / (n:2), 1, 1/theta * (1 - 1 / (2:n)))
yp = L_z_x(xp)
xlim = c(0, 1/theta)
plot(x, y, xlab = expression( x ), ylab = expression( L[z](x) ), xlim = xlim, type = "l", lwd = 4, sub = "(a)")
points(xp, yp, pch = c((n-1):1, 0, 1:(n-1)), col = "red", lwd = 2, cex = 2)
abline(h = 0, lty = "dashed")
abline(v = 1/theta, lty = "dashed")
savePlot(filename = "figure/y_z_x", type = c("pdf"))
savePlot(filename = "figure/y_z_x", type = c("jpg"))
## L(theta, a)
rm(list=ls(all=TRUE))
theta = 0.2
n = 10
L_z_a = function(theta, a) theta/((1/theta - 1)^2 * a) + theta/(1 - a) - 1/ (theta * (1/theta - 1)^2)
k2_theta = 1/((1/theta - 1)^2); k2_theta
a = seq(k2_theta * 1/n, (1 - 1/n), length.out = 50)
y = L_z_a(theta, a) 
ap = c(k2_theta * 1 / (n:2), theta, 1 - 1 / (2:n))
yp = L_z_a(theta, ap)
xlim = c(0, 1)
dev.new()
plot(a, y, xlab = expression( a ), ylab = expression( paste(L[z], "(", theta, ", a)") ), xlim = xlim, type = "l", lwd = 4, sub = "(b)")
points(ap, yp, pch = c((n-1):1, 0, 1:(n-1)), col = "red", lwd = 2, cex = 2)
abline(h = 0, lty = "dashed")
abline(v = 1, lty = "dashed")
savePlot(filename = "figure/y_z_theta_a", type = c("pdf"))
savePlot(filename = "figure/y_z_theta_a", type = c("jpg"))
q()
